//package com.ruoyi.edit.service.impl;
//
//import com.alibaba.druid.wall.violation.ErrorCode;
//import com.aliyun.oss.common.utils.DateUtil;
//import com.ruoyi.edit.service.WorkDayService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.io.IOException;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * *******************************
// * Created by Tim.
// * form com.matt
// * on 2018/10/9
// * *******************************
// */
//@Service
//public class WorkDayServiceImpl implements WorkDayService {
//
//    @Autowired
//    private WorkDayRepository workDayRepository;
//
//    @Override
//    public boolean refreshThreeMonth(String date) {
//        Date begin = DateUtil.parseToDate(date);
//        Date end = new Date(DateUtil.plusMonths(begin.getTime(), 3L));
//        Long days = DateUtil.betweenDays(begin, end);
//        List<WorkDay> workDayList = workDayRepository.findByDateBetween(begin, end);
//        for (long i = 0; i < days; i++) {
//            Date newDay = new Date(DateUtil.plusDays(begin.getTime(), i));
//            if (!contains(workDayList, newDay)){
//                workDayRepository.save(WorkDay.of(newDay, isWorkDay(newDay), DateUtil.isWeekEnd(newDay)));
//            }else
//                updateWorkDay(workDayList,newDay);
//        }
//        return false;
//    }
//
//    public boolean contains(List<WorkDay> dayList, Date date){
//        return dayList.stream().anyMatch(o-> DateUtil.toNormalString(o.getDate()).equals(DateUtil.toNormalString(date)));
//    }
//
//    public void updateWorkDay(List<WorkDay> dayList, Date date){
//        WorkDay workDay = dayList.stream().filter(o-> DateUtil.toNormalString(o.getDate()).equals(DateUtil.toNormalString(date))).collect(Collectors.toList()).get(0);
//        if (Objects.nonNull(workDay)){
//            workDay.setWorkDay(isWorkDay(date));
//            workDay.setWeekEnd(DateUtil.isWeekEnd(date));
//            workDayRepository.save(workDay);
//        }
//    }
//
//    private boolean isWorkDay(Date date){
//        try {
//            String url = String.format("http://api.goseek.cn/Tools/holiday?date=%s", DateUtil.millisToDateTime(date.getTime(), "yyyyMMdd"));
//            Map map = ModelUtil.objectMapper.readValue(HttpClientUtil.sendGet(url), Map.class);
//            return map.get("data").toString().equals("0");
//        } catch (IOException e) {
//           throw new BusinessException(ErrorCode.UNDEFINED, "日期更新失败");
//        }
//    }
//
//
//    @Override
//    public List<WorkDay> getWorkDayList(String month) {
//        month += "-01";
//        Date begin = DateUtil.getBeginOfMonth(month);
//        Date end = DateUtil.getEndOfMonth(month);
//        return workDayRepository.findByDateBetween(begin, end);
//    }
//
//
//    @Override
//    public List<WorkDay> getWorkDayList(String begin, String end) {
//        Date beginDate = DateUtil.parseToDate(begin);
//        Date endDate = DateUtil.parseToDate(end);
//        Long days = DateUtil.betweenDays(begin, end);
//        List<WorkDay> list = workDayRepository.findByDateBetween(beginDate, endDate);
//        if (list.size() < days+1)
//            throw new BusinessException(ErrorCode.DATE_FORMAT_ERROR, "工作日未初始化");
//        return list;
//    }
//
//}
